package entjava.poker;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entjava.poker.model.Card;
import entjava.poker.model.Game;
import entjava.poker.model.Player;
import entjava.poker.service.SmallBigService;

/**
 * Servlet implementation class ResetServlet
 */
@WebServlet("/ResetServlet")
public class ResetServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       Game game;
       ArrayList<Player> ls;
   	SmallBigService sbs;

   	
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		ServletContext context = request.getServletContext(); 
		//remove our game obj.
		game=(Game)request.getServletContext().getAttribute("game");
		
//		context.removeAttribute("game");
		//reset player stats
		 ls = (ArrayList<Player>)request.getServletContext().getAttribute("pList");	
		if(game.isResetGame()==false){
		sbs=(SmallBigService)request.getServletContext().getAttribute("smallbig");
		sbs.resetGame(ls);
		game.setCountRounds(0);
		game.setResetGame(true);
		System.out.println("IN RESET GAME post");
		}
		 
		RequestDispatcher view = request.getRequestDispatcher("success.jsp");
		view.forward(request, response);		
	}

}
